import  requests
import threading
from bs4 import BeautifulSoup
import re
import os.path
import time

for i in range(9175966,9175975):
  header = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67'}
  req = requests.get('https://www.biqooge.com/14_14451/%d.html' % i,
                   headers=header)
  result = req.content
  result = result.decode('gbk')
  title_re = re.compile(r'<h1>(.*?)</h1>')
  text_re = re.compile(r'&nbsp;&nbsp;&nbsp;&nbsp;([\s\S]*?) ')
  title = re.findall(title_re,result)
  text = re.findall(text_re,result)

  count = i - 9175965
  file = open("F:\学习资料\大二\python\大实验\\第%d章.txt" % count,'a')
  for sentence in text:
    sentence = sentence.replace('<br', '')
    file.write(sentence)
    file.write('\n')
  path = os.walk("F:\学习资料\大二\python\大实验\\第%d章.txt" % count)
  file.close()
  file = file = open("F:\学习资料\大二\python\大实验\\第%d章.txt" % count,'r')
  print("第%d章下载完毕" % count)

